<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../common/admin.asp"-->
<%
key=request.QueryString("key")
mark=request.QueryString("mark")
pay=request.QueryString("pay")
search=request.QueryString("search")

select case request.QueryString("mark")
case 0: title="交易失败的商品" : sqlsearch=" and mark=0"
case 1: title="等待审核的商品" : sqlsearch=" and mark=1 and ([order] not in(select [order] from orderlist where mark=0))"
case 2: title="有问题的商品" : sqlsearch=" and mark=2"
case 3: title="等待购买商品" : sqlsearch=" and mark=3"
case 4: title="等待卖家发货商品" : sqlsearch=" and mark=4"
case 5: title="已入库的商品" : sqlsearch=" and mark=5"
case 6: title="已创建包裹的商品" : sqlsearch=" and mark=6"
case 7: title="日本已寄出商品商品" : sqlsearch=" and mark=7"
case 8: title="已签收的商品" : sqlsearch=" and mark=8"
case 9: title="所有的商品" : sqlsearch=" and ([order] not in(select [order] from orderlist where mark=0))"
end select

if search="搜索" then
	  if key<>"" then
			sqlsearch=sqlsearch+" and ([order] like '%"&key&"%' or uid like '%"&replace(key,"U","")&"%')"
	  end if
end if
'分页-------------------------------------------------------
set Rs=server.CreateObject("ADODB.RecordSet")
sql="select count(sortid) from (Select ROW_NUMBER() OVER (order by id desc ) as sortid,* From orderdetail) as TempTable where 1=1 "&sqlsearch&""
Pager_Pagesize=10 '每页记录数
Rs.open sql,conn,1,1
Pager_TotalRecord=Rs(0) '总记录数
Rs.close
Pager_PageCount=int((Pager_TotalRecord/Pager_Pagesize)+0.99999) '计算总页数
CurrentPage=Request("page") '当前页
'如果不为数字则直接设置页码为1
if isnumeric(CurrentPage)=False Or CurrentPage="" then
	CurrentPage=1
'如果当前页数大于总页数，则直接设置页码为1
elseif  Clng(CurrentPage)>Pager_PageCount then
	CurrentPage=1
end if
Fieldsname=" id,[order],uid,url,pic,title,[content],Weight,price,Qty,WarehouseTime,PackageTime,mark,addtime,sortid"
orderBy=" Order by sortid asc"
'拆分SQL语句，必须是select开头，有唯一标识的列
if instr("select",sql)<>-1 then
	if CurrentPage = 1 then
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize  & Fieldsname)
	else  
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize   & Fieldsname) & " and sortid >(select max(sortid) from (" & replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize * (CurrentPage - 1)  & Fieldsname) & orderBy & ") AA)"
	end if
end if
sql = sql & orderBy
Rs.open sql,conn,1,1
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>main</title>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
<style>body {background-color: #eaece1;}</style>
</head>

<body>
<div class="main">
  <div class="main-title">查看</div>
  <div class="main-content">
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <tr>
    <td colspan="6" align="center">
    <form name="form" method="get" action="">
    <input name="key" type="text" id="key" value="<%=key%>" maxlength="50" />
    <input name="mark" type="hidden" value="<%=request.QueryString("mark")%>" />
    <input type="submit" name="search" value="搜索" />
    </form>
    </td>
    </tr>
    </table>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <form action="" method="post">
  <tr>
    <td align="center" bgcolor="#FFFFFF"><strong>选择</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong><span class="items">订单号</span></strong></td>
    <td align="center" bgcolor="#FFFFFF">会员ID</td>
    <td align="center" bgcolor="#FFFFFF"><strong><span class="items">会员</span></strong></td>
    <td align="center" bgcolor="#FFFFFF">图片</td>
    <td align="center" bgcolor="#FFFFFF">名称</td>
    <td align="center" bgcolor="#FFFFFF">备注</td>
    <td align="center" bgcolor="#FFFFFF">单价</td>
    <td align="center" bgcolor="#FFFFFF">购买数量</td>
    <td align="center" bgcolor="#FFFFFF">小计</td>
    <td align="center" bgcolor="#FFFFFF">入库时间</td>
    <td align="center" bgcolor="#FFFFFF">创建包裹时间</td>
    <td align="center" bgcolor="#FFFFFF"><strong><span class="items">状态</span></strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>操作</strong></td>
    <td bgcolor="#FFFFFF"><strong>添加时间</strong></td>
    </tr>
    <%do while not Rs.eof%>
  <tr>
    <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="checkbox" id="checkbox" value="<%=rs("id")%>" <%if request.QueryString("mark")="4" and rs("Weight")="0" then response.Write " disabled"%> />
      <input type="hidden" name="wid" value="<%=rs("id")%>" /></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("order")%></td>
    <td align="center" bgcolor="#FFFFFF">U<%=rs("uid")%></td>
    <td align="center" bgcolor="#FFFFFF"><%set rss=conn.execute("select mail from [user] where id="&rs("uid"))
		                               if not rss.eof then
		                               response.write rss("mail")
									   end if
									   set rss=nothing%></td>
    <td align="center" bgcolor="#FFFFFF"><a target="_blank" href="<%=rs("url")%>"><img src="<%=rs("pic")%>" height="50"></a></td>
    <td align="center" bgcolor="#FFFFFF" title="<%=rs("title")%>"><a target="_blank" href="<%=rs("url")%>"><%=left(rs("title"),30)%>.</a></td>
    <td align="center" bgcolor="#FFFFFF" title="<%=rs("content")%>"><%=left(rs("content"),30)%></td>
    <td align="center" bgcolor="#FFFFFF"><%=formatNumber(rs("price"),2,-1)%>日元</td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("Qty")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=formatNumber(cdbl(rs("price"))*cdbl(rs("Qty")),2,-1)%>日元</td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("WarehouseTime")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("PackageTime")%></td>
    <td align="center" bgcolor="#FFFFFF">
	
    <%
	  select case rs("mark")
	  case 0: response.Write "交易失败的商品"
	  case 1: response.Write "等待审核的商品"
	  case 2: response.Write "有问题的商品"
	  case 3: response.Write "等待购买商品"
	  case 4: response.Write "等待卖家发货商品"
	  case 5: response.Write "已入库的商品"
	  case 6: response.Write "已创建包裹的商品"
	  case 7: response.Write "日本已寄出商品商品"
	  case 8: response.Write "已签收的商品"
	  end select
	  %>
    
    </td>
    <td align="center" bgcolor="#FFFFFF"><%if request.QueryString("mark")="4" then%><input name="Weight<%=rs("id")%>" type="text" class="input" style="width:40px" value="<%=rs("Weight")%>" />克(g)<%else%>无<%end if%></td>
    <td bgcolor="#FFFFFF"><%=rs("addtime")%></td>
    </tr>
    <%
	Rs.movenext
	loop
	Rs.close
	Set Rs=nothing
	%>
    <tr>
      <td colspan="15" align="center" bgcolor="#FFFFFF" class="page">
              
           
            
            <%
			select case request.QueryString("mark")
	  case 0: response.Write "交易失败的商品"
	  case 1: response.Write "等待审核的商品  <input type=""submit"" name=""button"" value=""有问题的商品""><input type=""submit"" name=""button"" value=""等待购买商品"">"
	  case 2: response.Write "有问题的商品   <input type=""submit"" name=""button"" value=""交易失败的商品""><input type=""submit"" name=""button"" value=""等待购买商品"">"
	  case 3: response.Write "等待购买商品     <input type=""submit"" name=""button"" value=""交易失败的商品""><input type=""submit"" name=""button"" value=""等待卖家发货商品"">"
	  case 4: response.Write "等待卖家发货商品   <input type=""submit"" name=""button"" value=""保存商品重量""><input type=""submit"" name=""button"" value=""已入库的商品"">"
	  case 5: response.Write "已入库的商品   <input type=""submit"" name=""button"" value=""已创建包裹的商品"">"
	  case 6: response.Write "已创建包裹的商品   <input type=""submit"" name=""button"" value=""日本已寄出商品商品"">"
	  case 7: response.Write "日本已寄出商品商品   <input type=""submit"" name=""button"" value=""已签收的商品"">"
	  case 8: response.Write "已签收的商品"
	  end select
	  %>
            
            
      </td>
    </tr>
    </form>
    <tr>
    <td colspan="15" align="center" bgcolor="#FFFFFF" class="page">　
      <%
	siteurl=request.servervariables("document_name")
	%>
    <form action="<%=siteurl%>" method="get">
    共 <%=Pager_TotalRecord%> 条 第<%=CurrentPage%>页 / 共 <%=Pager_PageCount%> 页
		<%
		pageurl="key="&key&"&pay="&pay&"&mark="&mark&"&search="&search&"&"
		if CurrentPage=1 then
			response.Write(" 首页 ")
			response.Write(" 上一页 ")
		else
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page=1'>首页</a> ")
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& (CurrentPage-1) &"'>上一页</a> ")
		end if
		%>
		<%
		if Clng(CurrentPage)=Clng(Pager_PageCount) then
			response.Write(" 下一页 ")
			response.Write(" 尾页 ")
		else
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& (CurrentPage+1) &"'>下一页</a> ")
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& Pager_PageCount &"'>尾页</a> ")
		end if
		%>
		&nbsp;
		<input name="page" type="text" value="<%=CurrentPage%>" size="1" maxlength="10" />
        <input type="submit" name="button" value="跳转" />
        <input type="hidden" name="key" value="<%=key%>" />
        <input type="hidden" name="mark" value="<%=request.QueryString("mark")%>" />
        <input type="hidden" name="pay" value="<%=pay%>" />
        <input type="hidden" name="search" value="搜索" />
        </form>
      </td>
    </tr>
  </table>
</div>
</div>
</body>
</html>
<%
wid=request.Form("wid")
if wid<>"" then
   if request.Form("button")="保存商品重量" then
     wid=split(replace(wid," ",""),",")
     for i=0 to ubound(wid)
	 conn.execute("update orderdetail set Weight='"&request.Form("Weight"&wid(i))&"' where id = "&wid(i)&"")
	 next
	 response.Redirect "product.asp?mark="&request("mark")&"&page="&request.QueryString("page")&""
   end if
end if


checkbox=request.Form("checkbox")
if checkbox<>"" then

	if request.Form("button")="交易失败的商品" then
	
	    moneyuser=split(replace(checkbox," ",""),",")
        for f=0 to ubound(moneyuser)
		   set rss=conn.execute("select * from orderdetail where id="&moneyuser(f)&"")
		   if not rss.eof then
		       set rss2=conn.execute("select * from orderlist where [order]='"&rss("order")&"'")
			   if not rss2.eof then
	              '增加会员产品交易失败金额
			      conn.execute("update [user] set money=money+"&(cdbl(rss("price"))*cdbl(rss("Qty")))*cdbl(rss2("rate"))&" where id = "&rss("uid")&"")
			      '增加产品交易失败金额明细
			      set rsx=server.createobject("adodb.recordset")
				  sql="select * from Funds"
				  rsx.open sql,conn,1,3
				  rsx.addnew
				  rsx("money")=(cdbl(rss("price"))*cdbl(rss("Qty")))*cdbl(rss2("rate"))
				  rsx("user")=rss("uid")
				  rsx("order")=rss("order")
				  rsx("content")="商品交易失败"&rss("title")
				  rsx("paytype")="系统返款"
				  rsx("paymark")=1
				  rsx.update
				  rsx.close
				  set rsx=nothing
			   set rss2=nothing
			   end if
		   set rss=nothing
		   end if  
		next
		conn.execute("update orderdetail set mark=0 where id in ("&checkbox&")")

	elseif request.Form("button")="等待审核的商品" then
		conn.execute("update orderdetail set mark=1 where id in ("&checkbox&")")
	
	elseif request.Form("button")="有问题的商品" then
		conn.execute("update orderdetail set mark=2 where id in ("&checkbox&")")
	
	elseif request.Form("button")="等待购买商品" then
		conn.execute("update orderdetail set mark=3 where id in ("&checkbox&")")
		
	elseif request.Form("button")="等待卖家发货商品" then
		conn.execute("update orderdetail set mark=4 where id in ("&checkbox&")")
		
	elseif request.Form("button")="已入库的商品" then
		conn.execute("update orderdetail set mark=5,WarehouseTime='"&now()&"' where id in ("&checkbox&")")
		
	elseif request.Form("button")="已创建包裹的商品" then
		conn.execute("update orderdetail set mark=6,PackageTime='"&now()&"' where id in ("&checkbox&")")
		
	elseif request.Form("button")="日本已寄出商品商品" then
		conn.execute("update orderdetail set mark=7 where id in ("&checkbox&")")	
	
	elseif request.Form("button")="已签收的商品" then
		conn.execute("update orderdetail set mark=8 where id in ("&checkbox&")")
	
	end if
	response.Redirect "product.asp?mark="&request("mark")&"&page="&request.QueryString("page")&""
end if
%>